package com.gitee.feizns.quickstart.ding.talk.api.top.api.v2.department;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2DepartmentUpdateRequest;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.dingtalk.api.response.OapiV2DepartmentUpdateResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 更新部门（/topapi/v2/department/update）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/update-a-department-v2">创建部门（/topapi/v2/department/update）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/update-a-department-v2">服务端API 通讯录管理 部门管理 修改部门</a>
 * @author feizns
 * @since 2024/6/29
 */
public class Update {

    /**
     * 更新部门
     * @param accessToken 访问令牌
     * @param req 要求
     * @return {@link OapiV2DepartmentGetResponse.DeptGetResponse }
     */
    @SneakyThrows
    public static String execute(String accessToken, OapiV2DepartmentUpdateRequest req) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/update");
        OapiV2DepartmentUpdateResponse resp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(resp).getBody();
    }

}
